


from db_interface import db_interface


def ids_name_last_date(code="BK0451"):
    max_date = ""
    if not code:
        sql0 = f"select max(date) from dongcai_ids_data limit 1"
        query0 = list(db_interface.stock_base.select(sql0))
        max_date = query0[0][0].strftime("%Y-%m-%d")
    sql0 = f"select max(date) from dongcai_ids_data where code = '{code}' limit 1"
    query0 = list(db_interface.stock_base.select(sql0))
    if query0[0][0]:
        max_date = query0[0][0].strftime("%Y-%m-%d")
    ids_name = ""
    if code:
        sql = f"select name from ids_name_list where code = '{code}' limit 1 "
        query = list(db_interface.stock_base.select(sql))
        if query[0] and query0[0][0]:
            ids_name = query[0][0]

    res = {
        "ids_name": ids_name,
        "max_date": max_date
    }

    return res




if __name__ == '__main__':
    get_last_date()